<template>
  <div>
    <BasicModal
      :title="`${modalTitle}批量编辑`"
      @register="registerModal"
      @ok="submitFun"
      :closeFunc="closeFun"
    >
      <BasicForm :size="FORM_SIZE" :schemas="schemas" @register="registerFormInner" />
    </BasicModal>
  </div>
</template>

<script lang="ts" setup>
  import { ref } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { BasicForm, FormSchema, useForm } from '/@/components/Form';
  import { useFormSetting } from '/@/hooks/setting/useFormSetting';
  import { currentyOptions } from '/@/views/common/commonSetting';

  const emit = defineEmits(['closeFunEmit']);
  const FORM_SIZE = useFormSetting().getFormSize;
  const modalTitle = ref();
  const schemas = ref([] as any);
  const [registerModal] = useModalInner((data) => {
    modalTitle.value = data[0].name;
    console.log(data);
    const dataList = data.map((item) => {
      return {
        field: 'rate' + item.currency_id,
        component: 'InputNumber',
        label: currentyOptions[item.currency_id] + '返水',
        required: true,
      };
    });
    schemas.value = dataList;
    //console.log(data[0].name);
  });
  const [registerFormInner, { validate }] = useForm({
    showActionButtonGroup: false,
    labelWidth: 120,
    baseColProps: { span: 20 },
  });
  function closeFun() {
    schemas.value = [];
    emit('closeFunEmit');
    return true;
  }
  async function submitFun() {
    const values = await validate();
    console.log(values);
  }
</script>
